package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class DVDContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DVDContainer
{
    // instance variables - replace the example below with your own
    public ArrayList<DVD> dvds;
    private DVD dvd;
    

    /**
     * Constructor for objects of class DVDContainer
     */
    public DVDContainer()
    {
        // initialise instance variables
        dvds = new ArrayList<DVD>();
    }
    
    public ArrayList<DVD> dvdList()
    {
        return dvds;
    }
    
    public void addDVD(DVD dvd)
    {
        dvds.add(dvd);
    }
    
    public boolean deleteDVD(long id)
    {
        int index = 0;
        boolean found = false;
        DVD dvd = null;
        
        while(index < dvds.size() && !found)
        {
            dvd = dvds.get(index);
            
            if(dvd.getId() == id)
            {
                found = true;
            }
            else
            {
                index ++;
            }
        }
        
        if(found)
        {
            dvds.remove(index);
            return true;
        }
        else
        {
            return false;
        }
    }

    public DVD findDVD(String title)
    {
        int index = 0;
        boolean found = false;
        DVD dvd = null;
        
        while (index < dvds.size() && !found)
        {
            dvd = dvds.get(index);
            
            if(dvd.getTitle().equals(title))
            {
                found = true;
            }
            else
            {
                index ++;
            }
        }
        
        if (found)
        {
            return dvds.get(index);
        }
        
        else
        {
            System.out.println("Title not found");
            return null;
        }
    }
    
    public DVD findDVDid(long id)
    {
        int index = 0;
        boolean found = false;
        DVD dvd = null;
        
        while(index < dvds.size() && !found)
        {
            dvd = dvds.get(index);
            
            if(dvd.getId() == id)
            {
                found = true;
            }
            else
            {
                index ++;
            }
        }
        
        if(found)
        {
            return dvds.get(index);
        }
        
        else
        {
            
            return null;
        }
    }
}
